﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

public partial class Administration_BabyNameNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dlOrigin.DataSource = Entities.GetNamesOrigins();
            dlOrigin.DataBind();
        }
    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        string origin = (!string.IsNullOrEmpty(txtOrigin.Text)) ? txtOrigin.Text.Trim() : dlOrigin.SelectedValue;

        try
        {
            ChildrenNames newName = Entities.InsertOrUpdateBabyName(null, txtName.Text.Trim(), txtDescription.Text.Trim(), origin, dlSex.SelectedIndex);
            litMessage.Text = "Numele a fost adaugat cu succes in baza de date!";

            txtName.Text = string.Empty;
            txtOrigin.Text = string.Empty;
            txtDescription.Text = string.Empty;
            dlOrigin.DataSource = Entities.GetNamesOrigins();
            dlOrigin.DataBind();
        }
        catch (Exception ex)
        {
            litMessage.Text = ex.Message;
        }
    }
}
